<template>
    <div>
            <table>
                  <tr>
                       <td>头像</td>
                       <td>
                          <input type="file" @change="sc">
                          <img :src="'https://localhost:7059/' + data.Htp" style="width: 60px; height: 60px;" >
                       </td>
                  </tr>
                  <tr>
                       <td>活动信息</td>
                       <td>
                           <input type="text" v-model="data.Hname">
                       </td>
                  </tr>
                    <tr>
                       <td>活动状态</td>
                       <td>
                           <input type="radio" value="启用" name="aaa" v-model="data.Hzt">启用
                           <input type="radio" value="禁用" name="aaa" v-model="data.Hzt">禁用
                       </td>
                  </tr>
                    <tr>
                       <td>分类</td>
                       <td>
                           <select v-model="data.Hlxid">
                                 <option v-for="d in xl" :value="d.Fid">{{d.Fname}}</option>
                           </select>
                       </td>
                  </tr>
                    <tr>
                       <td>活动时间</td>
                       <td>
                         <input type="text" v-model="data.Hrq">
                       </td>
                  </tr>
                    <tr>
                       <td>活动地点</td>
                       <td>
                          <input type="text" v-model="data.Hdd">
                       </td>
                  </tr>
                    <tr>
                       <td>最后更新人</td>
                       <td>
                        <input type="text" v-model="data.Hgxr">
                       </td>
                  </tr>
                    <tr>
                       <td>最后更新日期</td>
                       <td>
                        <input type="text" v-model="data.Hgxsj">
                       </td>
                  </tr>
                    <tr>
                       <td></td>
                       <td>
                            <input type="button" value="添加" @click="add">
                       </td>
                  </tr>
            </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import {ref,onMounted} from 'vue'
import {useRouter} from 'vue-router'
import {useRoute} from 'vue-router'

const router = useRouter()
const route = useRoute()

const Fantian=()=>{
    const Hid = route.query.Hid;
    axios.get("https://localhost:7059/api/HD/Fantian",{params:{Hid:Hid}}).then(res=>{
        data.value = res.data
    })
}


const sc=(Yid:any)=>{
    var f = Yid.target.files[0]
    var fd = new FormData()
    fd.append("file",f)
    axios.post("https://localhost:7059/api/HD/SC",fd).then(res=>{
        data.value.Htp = res.data
    })
}

const data = ref({
    "Hid": 0,
    "Htp": "string",
    "Hname": "",
    "Hzt": "",
    "Hlxid": 0,
    "Hrq": "2025-07-13T00:00:00",
    "Hdd": "",
    "Hgxr": "",
    "Hgxsj": "2025-7-14",
})

const add=()=>{

    if(data.value.Hname == ""){
        alert("活动名称不能为空!");
        return ;
    }
      if(data.value.Hzt == ""){
        alert("状态不能为空!");
        return ;
    }
      if(data.value.Hdd == ""){
        alert("活动地点不能为空!");
        return ;
    }

    axios.post("https://localhost:7059/api/HD/Update",data.value).then(res=>{
        if(res.data>0){
            alert("修改成功!");
            router.push("/xianshi/");
        }
        else{
            alert("修改失败");
        }
    })
}

onMounted(()=>{
  Bang()
  Fantian()
})

const xl = ref([{
     "Fid": 1,
    "Fname": "文化才艺"
}])

const Bang=()=>{
    axios.get("https://localhost:7059/api/HD/Bang").then(res=>{
        xl.value = res.data
    })
}


</script>

<style scoped>

</style>